﻿function OpenDialog(title, url, height, width){
    if (url.indexOf("?") > 0)
        url = url + "&t=" + Math.random();
    else
        url = url + "?t=" + Math.random();
    $("#Dialog01>#Dialog01-iiframe").attr("src", url);
    $("#Dialog01").dialog({ height: height, width: width, modal: true, title: title });
    $("#Dialog01").dialog("open");
}
function CloseDialog(){
    $("#Dialog01").dialog("close");
}
function ReloadParentPage(pageName){
    window.parent.location.href = pageName;
}
function CloseDialogOpenDialog(title, url, height, width) { CloseDialog(); OpenDialog(title, url, height, width) };

function FormatPhone2(input) {
    MaskedText(input, '###-###-####');
}

function MaskedText(input, mask) {
    var key;

    if (window.event) {
        key = event.keyCode;
    }
    else if (e.which) {
        key = e.which;
    }
    if (key == 35 || key == 36 || key == 37 || key == 39 || key == 16 || key == 8 || key == 46)
        return;
    var text = input.value;
    var rs = '';
    var ch;
    var tLength = text.length;
    var index = 0;
    for (var i = 0; (i < mask.length && index < tLength); i++, index++) {
        switch (mask.charAt(i)) {
            case '#': //	Number
                while (index < tLength && (ch = text.charAt(index)) && (ch < '0' || ch > '9')) index++;
                if (index < tLength) rs += ch;
                break;
            case '*': //	Letter or Number
                while (index < tLength && (ch = text.charAt(index)) && (ch < '0' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < 'a') || ch > 'z')) index++;
                if (index < tLength) rs += ch;
                break;
            case '$': //	Letter
                while (index < tLength && (ch = text.charAt(index)) && (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z')) index++;
                if (index < tLength) rs += ch;
                break;
            default: //	Match exactly.
                var mCh = mask.charAt(i);
                ch = text.charAt(index);
                if (ch != mCh) index--;
                rs += mCh;
                break;
        }
    }
    input.value = rs;
}